<template>
    <div class="calendar-Top">
        <div class="data-select">
            <select v-model="year">
                <option v-for="item in years" :key="item" :value="item">{{item}}年</option>
            </select>
            <span @click="lastMonth">&lt;</span>
            <select v-model="month">
                <option v-for="item in months" :key="item" :value="item">{{ item }}月</option>
            </select>
            <span @click="nextMonth">&gt;</span>
        </div>
        <div class="today">
            <button @click="backToToday">今天</button>
        </div>
    </div>
</template>

<script setup>
import { useCounterStore } from '@/stores/calendar'
import { storeToRefs } from 'pinia'
//1.生成选择框数组
function createYears(){
  const years = []
  for (let i = 1900; i <= 2050; i++) {
    years.push(i)
  }
  return years
}

function createMonths(){
  const months = []
  for (let i = 1; i <= 12; i++) {
    months.push(i)
  }
  return months
}
const years = createYears()
const months = createMonths()

//导入选中的年,月,日
const { year, month } = storeToRefs(useCounterStore())
//导入切换日期的方法
const { lastMonth, nextMonth,backToToday } = useCounterStore()

</script>

<style lang="scss" scoped>
.calendar-Top {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 50px;
    background-image: linear-gradient(
        180deg,
        rgba(51,186,255,0.1) 0%,
        rgba(51,186,255,0) 100%
    );
    background-repeat: no-repeat;
    background-size: cover;
    .data-select{
        select{
            color: #333;
            padding: 4px 10px;
            border: 1px solid #d7d9e0;
            border-radius: 6px;
            &:hover{
                border: 1px solid #848691;
                cursor: pointer;
            }
            user-select:none;  //设置这个,鼠标左键就会选不中该选择框
        }
        span{
            color: #333;
            user-select: none;
            cursor: pointer;
        }
    }
    .today{
        button{
            color: #333;
            padding: 4px 20px;
            border: 1px solid #d7d9e0;
            border-radius: 6px;
            background-color: #fff;
            &:hover{
                border: 1px solid #848691;
                cursor: pointer;
            }
        }
    }
}
</style>
